<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>共享对象</title>
</head>

<body>
  <script src="../../node_modules/vue/dist/vue.js"></script>
  <div id="app">
    <counter></counter>
    <counter></counter>
    <counter></counter>
    <button @click="inc">increment</button>
  </div>
  <script>
    // 统一的状态
    const state = {
      count: 0
    }

    const Counter = {
      data() {
        return state; //返回统一的状态，并对状态变化监听
      },
      render(h) {
        return h('div',this.count)
      }
    }

    new Vue({
      el: '#app',
      components: {
        Counter
      },
      methods: {
        inc() {
          state.count++;
        }
      }
    })
  </script>
</body>

</html>